package org.jeecg.modules.online.cgform.converter.impl;

import org.jeecg.common.constant.ProvinceCityArea;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.converter.channel.ForeseeConvert;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;

/**
 *省市区换模式
 */
public class PcaConverter extends ForeseeConvert {

    ProvinceCityArea provinceCityArea;

    public PcaConverter(OnlCgformField onlCgformField){
        this.filed = onlCgformField.getDbFieldName();
        this.provinceCityArea = SpringContextUtils.getBean(ProvinceCityArea.class);
    }

    @Override
    public String converterToVal(String txt) {
        if(oConvertUtils.isEmpty(txt)){
            return null;
        }
        return provinceCityArea.getCode(txt);
    }

    @Override
    public String converterToTxt(String val) {
        if(oConvertUtils.isEmpty(val)){
            return null;
        }
        return provinceCityArea.getText(val);
    }

}
